﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;

/// <summary>
///DropDownListSearchShow 的摘要说明
/// </summary>
public class DropDownListSearchShow:BaseSearchShow
{
	public DropDownListSearchShow()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    #region ISearchTypeField 成员

    //public IEnumerable<Control> GetSearchFieldControls(ConfigColumns cCol)
    //{
    //    Panel p = new Panel();
    //    Literal lit = new Literal();
    //    lit.Text = cCol.SearchShowName;
    //    p.Controls.Add(lit);

    //    DropDownList ctrl = new DropDownList();
    //    ctrl.Items.Add(new ListItem("全部", string.Empty));
    //    ctrl.ID = cCol.ColumnName + "_SearchShow";
    //    ctrl.ValidationGroup = "Search";
    //    ctrl.AppendDataBoundItems = true;

    //    ctrl.DataTextField = cCol.SearchShowBindTextField;
    //    ctrl.DataValueField = cCol.SearchShowBindValueField;
    //    ctrl.DataSource = DBFactory.GetConn().exeTable(cCol.SearchShowSqlText);
    //    ctrl.DataBind();
    //    p.Controls.Add(ctrl);

    //    yield return p;
    //}

    #endregion

    protected override IEnumerable<Control> GetSearchContrls(ConfigColumns cCol)
    {
        DropDownList ctrl = new DropDownList();
        ctrl.Items.Add(new ListItem("全部", string.Empty));
        ctrl.ID = cCol.ColumnName + "_SearchShow";
        ctrl.ValidationGroup = "Search";
        ctrl.AppendDataBoundItems = true;
        Page page = HttpContext.Current.Handler as Page;
        if (page != null && page.IsPostBack)
        {
            ctrl.DataBound += new EventHandler(ctrl_DataBound);
        }
        ctrl.DataTextField = cCol.SearchShowBindTextField;
        ctrl.DataValueField = cCol.SearchShowBindValueField;
        ctrl.DataSource = DBFactory.GetConn().exeTable(cCol.SearchShowSqlText);
        ctrl.DataBind();

        yield return ctrl;
    }

    void ctrl_DataBound(object sender, EventArgs e)
    {
        Page page = HttpContext.Current.Handler as Page;
        DropDownList obj=(DropDownList)sender;
        if (page != null && page.IsPostBack)
        {
            string requestValue = HttpContext.Current.Request[obj.ID];
            if (!string.IsNullOrEmpty(requestValue))
            {
                obj.SelectedValue = requestValue;
            }
        }
    }
}
